/**
 * @author		Sergey Suzdalskiy
 * @e-mail:		sergey.suzdalskiy@gmail.com
 */
package ua.kiev.gcore.ui.controls
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextFieldAutoSize;

	public class Label extends Sprite
	{
		protected var background:Sprite;
		protected var autoSize:Boolean;
		private var _label:String;
		
		public function Label(ButtonBackground:Class, label:String = null, autoSize:Boolean = false)
		{
			background = new ButtonBackground();
			addChild(background);			
			this.autoSize = autoSize;
			this.label = label;
		}
		
		public function set label(value:String):void{
			if((value != null)&&(_label != value)){
				_label = value;
				if(background.hasOwnProperty("label")){					
					(background as Object).label.text = value;
					if(autoSize){
						(background as Object).label.autoSize = TextFieldAutoSize.LEFT;
					}
					((background as Object).control as Sprite).width = (background as Object).label.width + 10;
					dispatchEvent(new Event(Event.RESIZE));
					
				}
			}
		}
		public function get label():String{
			return _label;
		}
	}
}